import json as Json
from os import path as Path


class JsonDB():
    def __init__(self, path):
        self.path = path

        if Path.exists(path):
            with open(path, 'r+') as file:
                self.dic = Json.load(file)
        else:
            self.dic = {}

    def get(self, key):
        if self.hasKey(key):
            return self.dic[key]
        else:
            return None

    def set(self, key, value):
        self.dic[key] = value

    def hasKey(self, key):
        return key in self.dic

    def count(self):
        return self.dic.__len__()

    def save(self):
        with open(self.path, 'w') as file:
                Json.dump(self.dic, file)
            

